<%@page contentType="text/html;charset=utf-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>生成订单 - 当当网</title>
		<link href="../css/login.css" rel="stylesheet" type="text/css" />
		<link href="../css/page_bottom.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="../js/jquery-1.7.2.min.js" ></script>
		<script type="text/javascript">
		/* 验证表单 */
		uname = false;
		uaddress = false;
		upostcode = false;
		uphone = false;
		utel = false;
		
		$(function(){
				//验证是否为默认地址
				if($("#address").val() !=1){
					uname = true;
					uaddress = true;
					upostcode = true;
					uphone = true;
					utel = true;
					$("#receiveName").prop("readonly","true");
					$("#fullAddress").prop("readonly","true");
					$("#postalCode").prop("readonly","true");
					$("#phone").prop("readonly","true");
					$("#mobile").prop("readonly","true");
				}
			//验证用户名非空
			$("#receiveName").blur(function(){
				var pattern=/^.{1,10}$/;
				if(pattern.test($("#receiveName").val())){
					uname = true;
					$("#receiveNamefalse").text("收件人姓名可用！").css("color","green");
				}else{
					$("#receiveNamefalse").text("");
					$("#receiveNamefalse").text("收件人姓名必须是1~10位！").css("color","red");
					uname = false;
				}
			});
			//验证收件人详细地址非空
			$("#fullAddress").blur(function(){
				var pattern=/^.{1,50}$/;
				if(pattern.test($("#fullAddress").val())){
					$("#fulladdressflag").text("收件人详细可用！").css("color","green");
					uaddress = true;
				}else{
					$("#fulladdressflag").text("");
					$("#fulladdressflag").text("收件人详细地址必须是1~50位！").css("color","red");
					uaddress = false;
				}
			});
			//验证邮编格式
			$("#postalCode").blur(function(){
				var pattern=/^[0-9]{6}$/;
				if(pattern.test($("#postalCode").val())){
					$("#postcodeflag").text("邮编可用！").css("color","green");
					upostcode = true;
				}else{
					$("#postcodeflag").text("");
					$("#postcodeflag").text("邮编格式不对").css("color","red");
					upostcode = false;
				}
			});
			//验证电话
			$("#phone").blur(function(){
				var pattern=/^[0-9]{7,11}$/;
				if(pattern.test($("#phone").val())){
					$("#phoneflag").text("电话可用！").css("color","green");
					uphone = true;
				}else{
					$("#phoneflag").text("");
					$("#phoneflag").text("电话格式不对").css("color","red");
					uphone = false;
				}
			});
			//验证手机
			$("#mobile").blur(function(){
				var pattern=/^[0-9]{11}$/;
				if(pattern.test($("#mobile").val())){
					$("#mobilflag").text("手机号可用！").css("color","green");
					utel = true;
				}else{
					$("#mobilflag").text("");
					$("#mobilflag").text("手机号格式不对").css("color","red");
					utel = false;
				}
			});
			//所有验证条件均通过，提交表单
			$("#btnClientRegister1").click(function(){
				if(uname && uaddress && upostcode && uphone && utel){
					$("#f").submit();
				}
			});
		});
		
			function findAddress() {
				var id = $("#address").val();
				window.location.href='<s:url action="findAddressById" namespace="/address"/>?aid='+id;
			}
			
		</script>
		<style type="text/css">
			td{
				width: 600px;
			}
		</style>
	</head>
	<body>
		<%@include file="../common/head1.jsp"%>
		<div class="login_step">
			生成订单骤: 1.确认订单 >
			<span class="red_bold"> 2.填写送货地址</span> > 3.订单成功
		</div>
		<div class="fill_message">
			<p>
				选择地址：
				<select id="address" onchange="findAddress()">
					<option value="1" selected="selected">
						填写新地址
					</option>
					<s:iterator value="alist" var="a" status="status">
					<s:if test="#a.addressid == aid">
						<option value='<s:property value="#a.addressid"/>' selected="selected">地址<s:property value="#status.count" /> </option>
					</s:if>
					<s:else>
						<option value='<s:property value="#a.addressid"/>'>地址<s:property value="#status.count" /> </option>
					</s:else>
					</s:iterator>
				</select>
			</p>
			<form name="ctl00" method="post" action='<s:url action="addAdderss" namespace="/address"/>' id="f">
				<input type="hidden" name="aid" id="addressId" value="<s:property value="address.addressid"/>"/>
				<input type="hidden" name="totalprice" value='<s:property value="totalprice"/>'/>
				<table class="tab_login">
					<tr>
						<td valign="top" class="w1">
							收件人姓名：
						</td>
						<td>
							<input type="text" class="text_input" name="address.receivername" 
								id="receiveName" value='<s:property value="address.receivername"/>'/>
							<div class="text_left" id="nameValidMsg">
								<p>
									请填写有效的收件人姓名
								</p>
								<span id="receiveNamefalse"></span>
							</div>
						</td>
					</tr>
					<tr>
						<td valign="top" class="w1">
							收件人详细地址：
						</td>
						<td>
							<input type="text" name="address.receiveraddress" class="text_input"
								id="fullAddress" value='<s:property value="address.receiveraddress"/>'/>
							<div class="text_left" id="addressValidMsg">
								<p>
									请填写有效的收件人的详细地址
								</p>
								<span id="fulladdressflag"></span>
							</div>
						</td>
					</tr>
					<tr>
						<td valign="top" class="w1">
							邮政编码
						</td>
						<td>
							<input type="text" class="text_input" name="address.postcode"
								id="postalCode" value='<s:property value="address.postcode"/>'/>
							<div class="text_left" id="codeValidMsg">
								<p>
									请填写有效的收件人的邮政编码
								</p>
								<span id="postcodeflag"></span>
							</div>
						</td>
					</tr>
					<tr>
						<td valign="top" class="w1">
							电话
						</td>
						<td>
							<input type="text" class="text_input" name="address.phonenumber"
								id="phone" value='<s:property value="address.phonenumber"/>' />
							<div class="text_left" id="phoneValidMsg">
								<p>
									请填写有效的收件人的电话
								</p>
								<span id="phoneflag"></span>
							</div>
						</td>
					</tr>
					<tr>
						<td valign="top" class="w1">
							手机
						</td>
						<td>
							<input type="text" class="text_input" name="address.telephone"
								id="mobile" value='<s:property value="address.telephone"/>' />
							<div class="text_left" id="mobileValidMsg">
								<p>
									请填写有效的收件人的手机
								</p>
								<span id="mobilflag"></span>
							</div>
						</td>
					</tr>
				</table>

				<div class="login_in">

					<a href="order_info.jsp"><input id="btnClientRegister" class="button_1"
					type="button" value="取消" /></a>
			
				<input id="btnClientRegister1" class="button_1"
					type="button" value="下一步" />
				</div>
			</form>
		</div>
		<%@include file="../common/foot1.jsp"%>
	</body>
</html>

